﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Universum.Model.Services;
using Moq;
using Universum.Infrastructure.Persistence;
using System.Security.Principal;
using Universum.Infrastructure.Persistence.Queries;
using Universum.Model.Domain;

namespace Universum.Tests.Services
{
	[TestClass]
	public class SlugServiceTests
	{
		Mock<IRepository> _Repository;
		Mock<IPrincipal> _Principal;
		[TestInitialize]
		public void setup()
		{
			_Principal = new Mock<IPrincipal>();
			_Repository = new Mock<IRepository>();

			_Principal.SetupGet(property => property.Identity.Name)
				.Returns("mihai");
			_Repository.Setup(request => request.Query(It.IsAny<ArticleByUsernameAndSlug>()))
				.Returns(() => new Article[]{}.AsQueryable());
		}
		[TestMethod]
		public void should_convert_a_simple_string_to_slug()
		{
			// Arrange
			string test_string = "simple slug";
			var slugService = new FriendlyUrlServiceImpl(_Principal.Object,
				_Repository.Object);
			// Act
			var result = slugService.CreateSlugFrom(test_string);

			// Assert
			result.should_be_equal_to("simple-slug");
		}

		[TestMethod]
		public void should_convert_a_more_complete_example_to_slug()
		{
			// Arrange
			string test_string = "a more complete example of a slug";
			var slugService = new FriendlyUrlServiceImpl(_Principal.Object,
				_Repository.Object);
			// Act
			var result = slugService.CreateSlugFrom(test_string);

			// Assert
			result.should_be_equal_to("a-more-complete-example-of-a-slug");
		}
		[TestMethod]
		public void should_convert_even_examples_using_diacritics()
		{
			// Arrange
			string test_string = "În pădurea cu alune";
			var slugService = new FriendlyUrlServiceImpl(_Principal.Object,
				_Repository.Object);
			// Act
			var result = slugService.CreateSlugFrom(test_string);

			// Assert
			result.should_be_equal_to("n-p-durea-cu-alune");
		}
		[TestMethod]
		public void should_convert_example_using_numers()
		{
			// Arrange
			string test_string = "10 este o nota mare";
			var slugService = new FriendlyUrlServiceImpl(_Principal.Object,
				_Repository.Object);
			// Act
			var result = slugService.CreateSlugFrom(test_string);

			// Assert
			result.should_be_equal_to("10-este-o-nota-mare");
		}
		[TestMethod]
		public void should_convert_multiple_dashes_to_a_single_dash()
		{
			// Arrange
			string test_string = "10  este o notă mare";
			var slugService = new FriendlyUrlServiceImpl(_Principal.Object,
				_Repository.Object);
			// Act
			var result = slugService.CreateSlugFrom(test_string);

			// Assert
			result.should_be_equal_to("10-este-o-not-mare");
		}
		[TestMethod]
		public void should_remove_dash_from_front_and_back()
		{
			// Arrange
			string test_string = "În pădurea cu alune stă";
			var slugService = new FriendlyUrlServiceImpl(_Principal.Object,
				_Repository.Object);
			// Act
			var result = slugService.CreateSlugFrom(test_string);

			// Assert
			result.should_be_equal_to("n-p-durea-cu-alune-st");
		}
	}
}
